package leetcode;

public class IncreasingThreeNumber {

	public static void main(String[] args) {
		IncreasingThreeNumber number = new IncreasingThreeNumber();
		int[] nums = {100,121,108,109,110,201};
		int[] nums2 = {5,6,2,3,1,0,2,5};
		int[] nums3 = {5,4,6,7,1};
		System.out.println(number.increasingTriplet(nums));
		System.out.println(number.increasingTriplet(nums2));
		System.out.println(number.increasingTriplet(nums3));
		
	}
	
	public boolean increasingTriplet(int[] nums) {
		if (nums == null || nums.length <= 2) {
			return false;
		}
		int one = nums[0];
		Integer two = null;
		for (int i = 1; i < nums.length; i++) {
			if (two == null) {
				// that means we have't find the two increasing number.
				if (nums[i] > one) {
					two = nums[i];
				} else {
					one = nums[i];
				}
			} else {
				if (nums[i] > two) {
					// find the three increasing number.
					return true;
				} else if (nums[i] > one && nums[i] < two) {
					two = nums[i];
				} else if (nums[i] < one) {
					one = nums[i];
				}
			}
		}
		return false;
	}
}
